<template>
	<pro-table ref="protable" :loadDataUrl="loadDataUrl" rowKey="id" :columns="columns" :isRowSelection="true" @selectedRowChange="onSelectChange">
		<a-space slot="operation" slot-scope="{ text, record, index }">
			<a-button type="primary" size="small" @click="editRetrial(record)">编辑</a-button>
			<a-button type="danger" size="small" @click="showDeleteConfirm(record.id)">删除</a-button>
		</a-space>
		<template slot="footer">
			<a-button class="ant-btn-success" @click="editRetrial()">新增</a-button>
		</template>
		<!-- 新增或者编辑组件 -->
		<add-retrial-modal ref="addRetrialModal" @ok="handlerRefresh"></add-retrial-modal>
	</pro-table>
</template>

<script>
import { rowSelection } from '@/mixins'; //列表页面的一些公用方法
import addRetrialModal from './module/addRetrialModal'; //新增或编辑组件
import { api } from '@/api/index.js';
const columns = [
	{
		title: '区域',
		dataIndex: 'areaName',
		key: 'areaName',
		ellipsis: true
	},
	{
		title: '学校',
		dataIndex: 'schoolName',
		key: 'schoolName',
		/* 筛选列表 */
		searchInfo: {
			type: 'String', //筛选类型 参考filterbar readme
			value: 'schoolName' //查询字段，如果不配置，怎取key
		}
	},
	{
		title: '专业',
		dataIndex: 'majorCode',
		key: 'majorCode'
	},
	{
		title: '年份',
		dataIndex: 'years',
		key: 'years'
	},
	{
		title: '正常批分数线',
		dataIndex: 'retrialNormalLine',
		key: 'retrialNormalLine'
	},
	{
		title: '提前批分数线',
		dataIndex: 'retrialAdvanceLine',
		key: 'retrialAdvanceLine'
	},
	{
		title: '操作',
		key: 'operate',
		dataIndex: 'operate',
		scopedSlots: { customRender: 'operation' },
		align: 'center',
		width: 160
	}
];
export default {
	name: 'retriallist',
	mixins: [rowSelection],
	data() {
		return {
			columns: columns,
			filter: {},
			loadDataUrl: api.getRetrialList //查询列表接口，请在 api/index.js中配置
		};
	},
	components: { addRetrialModal },
	filters: {},
	methods: {
		/* 刷新列表当前页 */
		handlerRefresh() {
			this.$refs.protable.handlerRefresh();
		},
		/* 确认是否删除 */
		showDeleteConfirm(keys) {
			let _this = this;
			let title = '你确定要删除吗?';
			this.$confirm({
				title: title,
				content: '删除后数据将无法恢复',
				class: 'confirmbox',
				okType: 'danger',
				onOk() {
					_this.remove(keys);
				},
				onCancel() {}
			});
		},
		/*删除*/
		remove(delId) {
			this.$getAction(api.deleteRetrial, {
				id: delId
			}).then(res => {
				if (res.code == 200) {
					this.$message.success('删除成功');
					this.handlerRefresh();
				}
			});
		},
		/* 编辑 /添加*/
		editRetrial(record) {
			this.$refs.addRetrialModal.add(record);
		}
	}
};
</script>

<style></style>
